<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <title>用户中心-发征文</title>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="http://v3.bootcss.com/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
    <link href="/static/pc/cmgd.css" rel="stylesheet">
    <link href="/static/pc/style.css" rel="stylesheet">
    <link rel="stylesheet" href="/static/pc/swiper.3.2.0.min.css">

    <link rel="stylesheet" type="text/css" href="/static/admin/webupload/webuploader.css">
    <link rel="stylesheet" type="text/css" href="/static/admin/webupload/style.css">

    <!--[if lt IE 9]><script src="http://v3.bootcss.com/assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="http://v3.bootcss.com/assets/js/ie-emulation-modes-warning.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <script src="/static/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/static/admin/js/jquery.form.js"></script>
    <script src="/static/admin/js/plugins/layer/laydate/laydate.js"></script>
    <script src="/static/pc/js/layer/layer.js"></script>
    <script src="/static/admin/js/laypage/laypage.js"></script>
    <script src="/static/admin/js/laytpl/laytpl.js"></script>
    <link href="/static/admin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">

    <style>
        .list-group-item.active, .list-group-item.active:focus, .list-group-item.active:hover{
            background: #fff;
            color: #2fab87;
            border-color:#f5f5f5;
            border-bottom: 0px;
        }
        .list-group-item:first-child {border-radius: 0px;   }
        .fa{padding-right: 15px;font-size:18px;}
        .list-group-item{font-size:16px; border-top:0px;border-bottom: 1px #f5f5f5 solid;padding-top:20px;padding-bottom:20px; padding-left: 40px;
            border-left:0px;            border-right:0px;}
        .panel-heading{background: #f5f5f5;}

        .panel-primary>.panel-heading {
            padding: 25px 0 20px 0px;
            color: #000;
            background-color: #fff;
            border-color: #fff;
            border-bottom: 1px #f5f5f5 solid;
        }
        .myinfo{
            padding: 25px 20px 20px 20px;
            border-bottom: 2px #ffb400 solid;
        }

        .panel-primary {
            border-color: #fff;
        }


        body{background:#f5f5f5;}
        .col-xs-12, .col-sm-9{padding-left: 0px;}
        .btn-primary{
            background-color: #2fab87;
            border-color: #2fab87;
        }
        label{font-weight: 100;}

        .form-horizontal .control-label{text-align: left;letter-spacing:3px; width: 130px;}
        .webuploader-pick{ background-color: #2fab87;
            border-color: #2fab87;}
        .form-group{padding-top: 20px;}

    </style>
</head>

<body >
{include file="public/header4" /}

<div class="container body_bg" style="margin-top:80px;">

    <div class="row row-offcanvas row-offcanvas-right">
        <div class="col-xs-3 col-sm-3 sidebar-offcanvas" id="sidebar">

            <!--<div style="width: 100%;height:100px;padding-top: 20px;padding-left: 10px; background: #fff;" >-->
                <!--<div style="width:60px;float: left;margin-right:10px;">-->
                    <!--<img src="/uploads/face/{$member.head_img}" style="width: 60px;height: 60px;">-->
                <!--</div>-->
                <!--<div style="float: left;width: 178px;">-->
                    <!--<div style="width: 178px;overflow: hidden;padding-top: 3px;">{$member.nickname}</div>-->
                    <!--<div style="width: 178px;overflow: hidden;padding-top: 12px;">ID:{$member.account}</div>-->
                <!--</div>-->
            <!--</div>-->


            {include file="public/user_center" /}
        </div><!--/.sidebar-offcanvas-->
        <div class="col-xs-12 col-sm-9">

            <div class="panel panel-primary"  style="padding-left: 30px; min-height: 500px;">
                <div class="panel-heading">
                       <span class="myinfo">发征文</span>
                </div>
                <div class="panel-body">
                    <div class="wrapper wrapper-content animated fadeInRight">
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="ibox float-e-margins">
                                    <div class="ibox-title">
                                        <!--<div class="ibox-tools">-->
                                        <!--<a class="collapse-link">-->
                                        <!--<i class="fa fa-chevron-up"></i>-->
                                        <!--</a>-->
                                        <!--<a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">-->
                                        <!--<i class="fa fa-wrench"></i>-->
                                        <!--</a>-->
                                        <!--<a class="close-link">-->
                                        <!--<i class="fa fa-times"></i>-->
                                        <!--</a>-->
                                        <!--</div>-->
                                    </div>
                                    <div class="ibox-content">
                                        <form class="form-horizontal m-t" name="add" id="add" method="post" action="write_essay">

                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">标题</label>
                                                <div class="input-group col-sm-4">
                                                    <input id="title" type="text" class="form-control" name="title" placeholder="输入征文标题" value="{$info.title}">
                                                </div>
                                            </div>
                                            <div class="hr-line-dashed"></div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">所属分类</label>
                                                <div class="input-group col-sm-4">
                                                    <select class="form-control m-b chosen-select" name="cate_id" id="cate_id">
                                                        <option value="">==请选择==</option>
                                                        {if !empty($cate)}
                                                        {foreach name="cate" item="vo"}
                                                        <option value="{$vo.id}"  {if condition="$info.cate_id == $vo.id"} selected{/if}   >{$vo.name}</option>
                                                            {if !empty($vo.son)}
                                                            {foreach name="vo.son" item="vv"}
                                                            <option value="{$vv.id}"  {if condition="$info.cate_id == $vv.id"} selected{/if}   >&nbsp;&nbsp;---{$vv.name}</option>
                                                            {/foreach}
                                                            {/if}
                                                        {/foreach}
                                                        {/if}
                                                    </select>
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">征文对象</label>
                                                <div class="input-group col-sm-4">
                                                    <input id="object_people" type="text" class="form-control" name="object_people" placeholder="输入征文对象" value="">
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">截止时间</label>
                                                <div class="input-group col-sm-4">
                                                    <input type="text" name="end_time" onclick="laydate()" id="end_time" class="form-control layer-date" placeholder="征文截止时间"/>
                                                </div>
                                            </div>



                                            <div class="hr-line-dashed"></div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">描述</label>
                                                <div class="input-group col-sm-4">
                                                    <textarea type="text" rows="5" name="remark" id="remark" placeholder="输入文章描述" class="form-control">{$info.remark}</textarea>
                                                </div>
                                            </div>
                                            <div class="hr-line-dashed"></div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">封面</label>
                                                <div class="input-group col-sm-4">
                                                    <input type="hidden" id="data_photo" name="photo" value="{$info.photo}">
                                                    <div id="fileList" class="uploader-list" style="float:right"></div>
                                                    <div id="imgPicker" style="float:left">选择图片</div>
                                                    <img id="img_data" height="100px" style="float:left;margin-left: 50px;margin-top: -10px;" src="/uploads/images/{$info.photo}"  onerror="this.src='/static/admin/images/no_img.jpg'"     />
                                                </div>
                                            </div>
                                            <div class="hr-line-dashed"></div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label " for="myEditor">内容</label>
                                                <div class="input-group col-sm-9">
                                                    <script src="/static/admin/ueditor/ueditor.config.js" type="text/javascript"></script>
                                                    <script src="/static/admin/ueditor/ueditor.all.js" type="text/javascript"></script>
                                                    <textarea name="content" style="width:90%" id="myEditor">{$info.content}</textarea>
                                                    <script type="text/javascript">
                                                        var editor = UE.getEditor('myEditor',{
                                                            //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
                                                            toolbars:[['undo', 'redo', '|',
                                                                'bold', 'italic', 'underline', 'formatmatch', 'forecolor','paragraph', 'fontfamily', 'fontsize', '|',
                                                                'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'simpleupload', 'insertimage', 'insertvideo','attachment'
//                                            'directionalityltr', 'directionalityrtl', 'indent', '|', 'touppercase', 'tolowercase', '|',  'link', 'unlink', 'anchor', '|',  'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
//                                            'emotion', 'scrawl', 'music','map', 'gmap', 'insertframe', 'insertcode', 'webapp','template', 'background', '|','fullscreen',   'splittocols', 'charts', '|',
//                                            'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|','print', 'preview', 'searchreplace', 'drafts', 'help',  'pagebreak', 'splittorows',
//                                            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells',
                                                            ]],
//                                                            autoClearinitialContent:true,
                                                            wordCount:false,
                                                            elementPathEnabled:false,
                                                        });
                                                    </script>
                                                </div>
                                            </div>

                                            <div class="hr-line-dashed"></div>
                                            <div class="form-group">
                                                <div class="col-sm-4 col-sm-offset-3">
                                                    <button class="btn btn-primary" type="submit"> 提&nbsp;&nbsp;&nbsp;交</button>&nbsp;&nbsp;&nbsp;
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div><!--/row-->

    <hr>

    <footer style="text-align: center;">
        <p>&copy; Company 2017</p>
    </footer>

</div><!--/.container-->


<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->

<script type="text/javascript" src="/static/admin/webupload/webuploader.min.js"></script>

<script type="text/javascript">
    var $list = $('#fileList');
    //上传图片,初始化WebUploader
    var uploader = WebUploader.create({

        auto: true,// 选完文件后，是否自动上传。
        swf: '/static/admin/js/webupload/Uploader.swf',// swf文件路径
        server: "{:url('Web/Upload/upload')}",// 文件接收服务端。
        duplicate :true,// 重复上传图片，true为可重复false为不可重复
        pick: '#imgPicker',// 选择文件的按钮。可选。

        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },

        'onUploadSuccess': function(file, data, response) {
            $("#data_photo").val(data._raw);
            $("#img_data").attr('src', '/uploads/images/' + data._raw).show();
        }
    });

    uploader.on( 'fileQueued', function( file ) {
        $list.html( '<div id="' + file.id + '" class="item">' +
                '<h4 class="info">' + file.name + '</h4>' +
                '<p class="state">正在上传...</p>' +
                '</div>' );
    });

    // 文件上传成功
    uploader.on( 'uploadSuccess', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传成功！');
    });

    // 文件上传失败，显示上传出错。
    uploader.on( 'uploadError', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传出错!');
    });

    function save_cg(){
        $('#add').attr('action','cg_add_article').submit();
    }

    $(function(){
        $('#add').ajaxForm({
            beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });

        function checkForm(){



                if( '' == $.trim($('#title').val())){
                    layer.msg('标题不能为空', {icon: 5,time:1500,shade: 0.1}, function(index){
                        layer.close(index);
                    });
                    return false;
                }

                if( '' == $.trim($('#cate_id').val())){
                    layer.msg('分类不能为空', {icon: 5,time:1500,shade: 0.1}, function(index){
                        layer.close(index);
                    });
                    return false;
                }

                if( '' == $.trim($('#object_people').val())){
                    layer.msg('征文对象不能为空', {icon: 5,time:1500,shade: 0.1}, function(index){
                        layer.close(index);
                    });
                    return false;
                }

                if( '' == $.trim($('#end_time').val())){
                    layer.msg('征文截止时间不能为空', {icon: 5,time:1500,shade: 0.1}, function(index){
                        layer.close(index);
                    });
                    return false;
                }

                if( '' == $.trim($('#remark').val())){
                    layer.msg('描述不能为空', {icon: 5,time:1500,shade: 0.1}, function(index){
                        layer.close(index);
                    });
                    return false;
                }

                if( '' == $.trim($('#data_photo').val())){
                    layer.msg('请上传图片', {icon: 5,time:1500,shade: 0.1}, function(index){
                        layer.close(index);
                    });
                    return false;
                }

//            if( '' == $.trim($('#content').val())){
//                layer.msg('内容不能为空', {icon: 5,time:1500,shade: 0.1}, function(index){
//                    layer.close(index);
//                });
//                return false;
//            }


        }

        function complete(data) {
            if (data.code == 1) {
                layer.msg(data.msg, {icon: 6, time: 1500, shade: 0.1}, function (index) {
                    layer.close(index);

                    window.location.href = "{:url('article/myessay')}";
                    //window.location.href="{:url('article/index')}";

                });
            } else {
                layer.msg(data.msg, {icon: 5, time: 1500, shade: 0.1}, function (index) {
                    layer.close(index);
                });
                return false;
            }
        }
    });



</script>
</body>
</html>
